package com.myph.chart;

import java.util.ArrayList;
import java.util.List;

import org.achartengine.ChartFactory;
import org.achartengine.chart.PointStyle;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import com.android.volley.RedirectError;
import com.myph.model.Util;

import android.R.string;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint.Align;

public class ShowChart extends AbstractDemoChart {
    
    public double maxX = 5.0;
    public double xArray[];
    public double yArray[];
    public String title;
    
    public void setTitle(String title){
    	this.title = title;
    }
    public String getName() {
        return "pH measurement";
    }

    public String getDesc() {
        return "pH";
    }
    public void setXArray(double[] xArr){
        xArray = xArr;
    }
    public void setYArray(double[] yArr){
        yArray = yArr;
    }
    public Intent execute(Context context) {
        String[] titles = new String[] { "STM32S411"};
        List<double[]> x = new ArrayList<double[]>();
        
        x.add(xArray);
        
        List<double[]> values = new ArrayList<double[]>();
        values.add(yArray);
        
        int[] colors = new int[] { Color.BLUE};
        PointStyle[] styles = new PointStyle[] { PointStyle.TRIANGLE};
        
        XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
        int length = renderer.getSeriesRendererCount();
        for (int i = 0; i < length; i++) {
            ((XYSeriesRenderer) renderer.getSeriesRendererAt(i))
                    .setFillPoints(true);
        }
        renderer.setLegendTextSize(Util.dip2px(context, 7));
        renderer.setApplyBackgroundColor(true);
        renderer.setLabelsTextSize(Util.dip2px(context,15));
        renderer.setAxisTitleTextSize(Util.dip2px(context,16)); 
        renderer.setPointSize(15);
        renderer.setChartTitleTextSize(Util.dip2px(context,16));
        renderer.setDisplayChartValues(true);
        renderer.setGridColor(Color.WHITE);

        
        setChartSettings(renderer, title, "time",
                "pH", 0.0, maxX, 0.0, 14.0, Color.LTGRAY, Color.LTGRAY);
        
        renderer.setXLabels(12);
        renderer.setYLabels(10);
        renderer.setShowGrid(true);
        renderer.setXLabelsAlign(Align.RIGHT);
        renderer.setYLabelsAlign(Align.LEFT);
        renderer.setZoomButtonsVisible(true);
        renderer.setMargins(new int[]{30,70,0,10});
        renderer.setPanLimits(new double[] { -1.0, maxX*1.5, 0.0, 14.0 }); 
        renderer.setZoomLimits(new double[] { -1.0, maxX*1.5, 0.0, 14.0 });
        Intent intent = ChartFactory.getLineChartIntent(context,
                buildDataset(titles, x, values), renderer,
                "pH");
        return intent;
    }

}